//
//  YNSSaveView.m
//  HNBaseProject
//
//  Created by TR on 2024/7/24.
//

#import "YNSSaveView.h"

@implementation YNSSaveView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame])
    {
        self.backgroundColor = RGBA_COLOR(0, 0, 0, 0.4);
        
        self.bgView = [[UIView alloc]init];
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius=19;
        [self addSubview:self.bgView];
        [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.mas_centerX).offset(0);
            make.centerY.equalTo(self.mas_centerY).offset(0);
            make.width.offset(kScreenW-60);
            make.height.offset(kRealValue(441));
        }];
        CAGradientLayer *gl = [CAGradientLayer layer];
        gl.frame = CGRectMake(0,0,kScreenW-60,kRealValue(441));
        gl.startPoint = CGPointMake(0.5, 0);
        gl.endPoint = CGPointMake(0.5, 1);
        gl.colors = @[(__bridge id)[UIColor colorWithHexString:@"#DBEDFF"].CGColor, (__bridge id)[UIColor colorWithHexString:@"#FFFFFF"].CGColor];
        gl.locations = @[@(0), @(1.0f)];
        [self.bgView.layer addSublayer:gl];
        
        self.tLab1 = [[UILabel alloc]init];
        self.tLab1.text = @"====== 选择保存格式 ======";
        self.tLab1.textColor = [UIColor colorWithHexString:@"#333333"];
        self.tLab1.font = PFRFontMedium(15);
        [self.bgView addSubview:self.tLab1];
        [self.tLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.bgView.mas_centerX).offset(0);
            make.top.offset(24);
        }];
        
        self.tLab2 = [[UILabel alloc]init];
        self.tLab2.text = @"只保存视频";
        self.tLab2.textColor = [UIColor colorWithHexString:@"#000000"];
        self.tLab2.font = PFRFontSemibold(17);
        [self.bgView addSubview:self.tLab2];
        [self.tLab2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(24);
            make.top.equalTo(self.tLab1.mas_bottom).offset(37);
        }];
        
        self.selectBtn1 = [[ExpandButton alloc]init];
        [self.selectBtn1 setTitle:@"MOV" forState:UIControlStateNormal];
        [self.selectBtn1 setTitleColor:[UIColor colorWithHexString:@"#97A2AC"] forState:UIControlStateNormal];
        [self.selectBtn1 setImage:[UIImage imageNamed:@"weixuanze"] forState:UIControlStateNormal];
        [self.selectBtn1 setTitleColor:[UIColor colorWithHexString:@"#1D8EFF"] forState:UIControlStateSelected];
        [self.selectBtn1 setImage:[UIImage imageNamed:@"xuanze"] forState:UIControlStateSelected];
        self.selectBtn1.titleLabel.font = [UIFont systemFontOfSize:14];
        self.selectBtn1.selected = NO;
        self.selectBtn1.tag = 0;
        [self.selectBtn1 addTarget:self action:@selector(choseClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.selectBtn1];
        [self.selectBtn1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.tLab2.mas_bottom).offset(19);
            make.left.offset(35);
            make.height.offset(20);
            make.width.offset(50);
        }];
        
        self.selectBtn2 = [[ExpandButton alloc]init];
        [self.selectBtn2 setTitle:@"MP4" forState:UIControlStateNormal];
        [self.selectBtn2 setTitleColor:[UIColor colorWithHexString:@"#97A2AC"] forState:UIControlStateNormal];
        [self.selectBtn2 setImage:[UIImage imageNamed:@"weixuanze"] forState:UIControlStateNormal];
        [self.selectBtn2 setTitleColor:[UIColor colorWithHexString:@"#1D8EFF"] forState:UIControlStateSelected];
        [self.selectBtn2 setImage:[UIImage imageNamed:@"xuanze"] forState:UIControlStateSelected];
        self.selectBtn2.titleLabel.font = [UIFont systemFontOfSize:14];
        self.selectBtn2.selected = NO;
        self.selectBtn2.tag = 1;
        [self.selectBtn2 addTarget:self action:@selector(choseClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.selectBtn2];
        [self.selectBtn2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.tLab2.mas_bottom).offset(19);
            make.left.equalTo(self.selectBtn1.mas_right).offset(40);
            make.height.offset(20);
            make.width.offset(50);
        }];
        
        self.tLab3 = [[UILabel alloc]init];
        self.tLab3.text = @"保存图片和视频";
        self.tLab3.textColor = [UIColor colorWithHexString:@"#000000"];
        self.tLab3.font = PFRFontSemibold(17);
        [self.bgView addSubview:self.tLab3];
        [self.tLab3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(24);
            make.top.equalTo(self.selectBtn1.mas_bottom).offset(29);
        }];
        
        self.tLab4 = [[UILabel alloc]init];
        self.tLab4.text = @"图片格式";
        self.tLab4.textColor = [UIColor colorWithHexString:@"#666666"];
        self.tLab4.font = PFRFont(16);
        [self.bgView addSubview:self.tLab4];
        [self.tLab4 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.bgView.mas_centerX).offset(0);
            make.top.equalTo(self.tLab3.mas_bottom).offset(15);
        }];
        
        self.selectBtn3 = [[ExpandButton alloc]init];
        [self.selectBtn3 setTitle:@"JPG" forState:UIControlStateNormal];
        [self.selectBtn3 setTitleColor:[UIColor colorWithHexString:@"#97A2AC"] forState:UIControlStateNormal];
        [self.selectBtn3 setImage:[UIImage imageNamed:@"weixuanze"] forState:UIControlStateNormal];
        [self.selectBtn3 setTitleColor:[UIColor colorWithHexString:@"#1D8EFF"] forState:UIControlStateSelected];
        [self.selectBtn3 setImage:[UIImage imageNamed:@"xuanze"] forState:UIControlStateSelected];
        self.selectBtn3.titleLabel.font = [UIFont systemFontOfSize:14];
        self.selectBtn3.selected = NO;
        self.selectBtn3.tag = 0;
        [self.selectBtn3 addTarget:self action:@selector(choseClick1:) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.selectBtn1];
        [self.bgView addSubview:self.selectBtn3];
        [self.selectBtn3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.tLab4.mas_bottom).offset(10);
            make.left.offset(35);
            make.height.offset(20);
            make.width.offset(50);
        }];
        self.selectBtn4 = [[ExpandButton alloc]init];
        [self.selectBtn4 setTitle:@"PNG" forState:UIControlStateNormal];
        [self.selectBtn4 setTitleColor:[UIColor colorWithHexString:@"#97A2AC"] forState:UIControlStateNormal];
        [self.selectBtn4 setImage:[UIImage imageNamed:@"weixuanze"] forState:UIControlStateNormal];
        [self.selectBtn4 setTitleColor:[UIColor colorWithHexString:@"#1D8EFF"] forState:UIControlStateSelected];
        [self.selectBtn4 setImage:[UIImage imageNamed:@"xuanze"] forState:UIControlStateSelected];
        self.selectBtn4.titleLabel.font = [UIFont systemFontOfSize:14];
        self.selectBtn4.selected = NO;
        self.selectBtn4.tag = 1;
        [self.selectBtn4 addTarget:self action:@selector(choseClick1:) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.selectBtn4];
        [self.selectBtn4 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.tLab4.mas_bottom).offset(10);
            make.left.equalTo(self.selectBtn3.mas_right).offset(40);
            make.height.offset(20);
            make.width.offset(50);
        }];
        self.selectBtn5 = [[ExpandButton alloc]init];
        [self.selectBtn5 setTitle:@"WEB" forState:UIControlStateNormal];
        [self.selectBtn5 setTitleColor:[UIColor colorWithHexString:@"#97A2AC"] forState:UIControlStateNormal];
        [self.selectBtn5 setImage:[UIImage imageNamed:@"weixuanze"] forState:UIControlStateNormal];
        [self.selectBtn5 setTitleColor:[UIColor colorWithHexString:@"#1D8EFF"] forState:UIControlStateSelected];
        [self.selectBtn5 setImage:[UIImage imageNamed:@"xuanze"] forState:UIControlStateSelected];
        self.selectBtn5.titleLabel.font = [UIFont systemFontOfSize:14];
        self.selectBtn5.selected = NO;
        self.selectBtn5.tag = 2;
        [self.selectBtn5 addTarget:self action:@selector(choseClick1:) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.selectBtn5];
        [self.selectBtn5 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.tLab4.mas_bottom).offset(10);
            make.left.equalTo(self.selectBtn4.mas_right).offset(40);
            make.height.offset(20);
            make.width.offset(50);
        }];
        self.tLab5 = [[UILabel alloc]init];
        self.tLab5.text = @"视频格式";
        self.tLab5.textColor = [UIColor colorWithHexString:@"#666666"];
        self.tLab5.font = PFRFont(16);
        [self.bgView addSubview:self.tLab5];
        [self.tLab5 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.bgView.mas_centerX).offset(0);
            make.top.equalTo(self.selectBtn5.mas_bottom).offset(20);
        }];
        
        self.selectBtn6 = [[ExpandButton alloc]init];
        [self.selectBtn6 setTitle:@"JPG" forState:UIControlStateNormal];
        [self.selectBtn6 setTitleColor:[UIColor colorWithHexString:@"#97A2AC"] forState:UIControlStateNormal];
        [self.selectBtn6 setImage:[UIImage imageNamed:@"weixuanze"] forState:UIControlStateNormal];
        [self.selectBtn6 setTitleColor:[UIColor colorWithHexString:@"#1D8EFF"] forState:UIControlStateSelected];
        [self.selectBtn6 setImage:[UIImage imageNamed:@"xuanze"] forState:UIControlStateSelected];
        self.selectBtn6.titleLabel.font = [UIFont systemFontOfSize:14];
        self.selectBtn6.selected = NO;
        self.selectBtn6.tag = 2;
        [self.selectBtn6 addTarget:self action:@selector(choseClick2:) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.selectBtn6];
        [self.selectBtn6 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.tLab5.mas_bottom).offset(19);
            make.left.offset(35);
            make.height.offset(20);
            make.width.offset(50);
        }];
        self.selectBtn7 = [[ExpandButton alloc]init];
        [self.selectBtn7 setTitle:@"PNG" forState:UIControlStateNormal];
        [self.selectBtn7 setTitleColor:[UIColor colorWithHexString:@"#97A2AC"] forState:UIControlStateNormal];
        [self.selectBtn7 setImage:[UIImage imageNamed:@"weixuanze"] forState:UIControlStateNormal];
        [self.selectBtn7 setTitleColor:[UIColor colorWithHexString:@"#1D8EFF"] forState:UIControlStateSelected];
        [self.selectBtn7 setImage:[UIImage imageNamed:@"xuanze"] forState:UIControlStateSelected];
        self.selectBtn7.titleLabel.font = [UIFont systemFontOfSize:14];
        self.selectBtn7.selected = NO;
        self.selectBtn7.tag = 3;
        [self.selectBtn7 addTarget:self action:@selector(choseClick2:) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.selectBtn7];
        [self.selectBtn7 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.tLab5.mas_bottom).offset(19);
            make.left.equalTo(self.selectBtn6.mas_right).offset(40);
            make.height.offset(20);
            make.width.offset(50);
        }];
        self.selectBtn8 = [[ExpandButton alloc]init];
        [self.selectBtn8 setTitle:@"WEB" forState:UIControlStateNormal];
        [self.selectBtn8 setTitleColor:[UIColor colorWithHexString:@"#97A2AC"] forState:UIControlStateNormal];
        [self.selectBtn8 setImage:[UIImage imageNamed:@"weixuanze"] forState:UIControlStateNormal];
        [self.selectBtn8 setTitleColor:[UIColor colorWithHexString:@"#1D8EFF"] forState:UIControlStateSelected];
        [self.selectBtn8 setImage:[UIImage imageNamed:@"xuanze"] forState:UIControlStateSelected];
        self.selectBtn8.titleLabel.font = [UIFont systemFontOfSize:14];
        self.selectBtn8.selected = NO;
        self.selectBtn8.tag = 4;
        [self.selectBtn8 addTarget:self action:@selector(choseClick2:) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.selectBtn8];
        [self.selectBtn8 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.tLab5.mas_bottom).offset(19);
            make.left.equalTo(self.selectBtn7.mas_right).offset(40);
            make.height.offset(20);
            make.width.offset(50);
        }];
        
        self.cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        [self.cancelBtn setTitleColor:[UIColor colorWithHexString:@"#7D7C81"] forState:UIControlStateNormal];
        self.cancelBtn.backgroundColor = [UIColor whiteColor];
        self.cancelBtn.layer.masksToBounds = YES;
        self.cancelBtn.layer.cornerRadius = 21;
        self.cancelBtn.layer.borderColor = [UIColor colorWithHexString:@"#CCCCCC"].CGColor;
        self.cancelBtn.layer.borderWidth = 1;
        self.cancelBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.cancelBtn addTarget:self action:@selector(cancelClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.cancelBtn];
        [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(24);
            make.top.equalTo(self.selectBtn8.mas_bottom).offset(38);
            make.width.offset((kScreenW-120)/2);
            make.height.offset(42);
        }];
        
        self.comfireBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.comfireBtn setTitle:@"确认" forState:UIControlStateNormal];
        [self.comfireBtn setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
        self.comfireBtn.backgroundColor = [UIColor colorWithHexString:@"#1D8EFF"];
        self.comfireBtn.layer.masksToBounds = YES;
        self.comfireBtn.layer.cornerRadius = 21;
        self.comfireBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.comfireBtn addTarget:self action:@selector(comfireClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.comfireBtn];
        [self.comfireBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.offset(-24);
            make.top.equalTo(self.selectBtn8.mas_bottom).offset(38);
            make.width.offset((kScreenW-120)/2);
            make.height.offset(42);
        }];
    }
    return self;
}

#pragma mark------cancelClick------
- (void)cancelClick{
    [self removeFromSuperview];
}

#pragma mark------comfireClick------
- (void)comfireClick{
    
}

#pragma mark--------只保存视频------
- (void)choseClick:(UIButton*)btn {
    self.videoType = [NSString stringWithFormat:@"%ld",(long)btn.tag];
    self.imgType = @"";
    if (btn.tag==0)
    {
        self.selectBtn1.selected = YES;
        self.selectBtn2.selected = NO;
    }
    else {
        self.selectBtn2.selected = YES;
        self.selectBtn1.selected = NO;
    }
    self.selectBtn3.selected = NO;
    self.selectBtn4.selected = NO;
    self.selectBtn5.selected = NO;
    self.selectBtn6.selected = NO;
    self.selectBtn7.selected = NO;
    self.selectBtn8.selected = NO;
}
#pragma mark--------图片选择------
- (void)choseClick1:(UIButton*)btn {
    self.imgType = [NSString stringWithFormat:@"%ld",(long)btn.tag];
    if ([self.videoType intValue]<2)
    {
        self.videoType=@"";
    }
    if (btn.tag==0)
    {
        self.selectBtn3.selected = YES;
        self.selectBtn4.selected = NO;
        self.selectBtn5.selected = NO;
    }
    else if (btn.tag==1){
        self.selectBtn3.selected = NO;
        self.selectBtn4.selected = YES;
        self.selectBtn5.selected = NO;
    }
    else {
        self.selectBtn3.selected = NO;
        self.selectBtn4.selected = NO;
        self.selectBtn5.selected = YES;
    }
    self.selectBtn1.selected = NO;
    self.selectBtn2.selected = NO;
}
#pragma mark--------视频选择------
- (void)choseClick2:(UIButton*)btn {
    self.videoType = [NSString stringWithFormat:@"%ld",(long)btn.tag];
    if (btn.tag==2)
    {
        self.selectBtn6.selected = YES;
        self.selectBtn7.selected = NO;
        self.selectBtn8.selected = NO;
    }
    else if (btn.tag==3){
        self.selectBtn6.selected = NO;
        self.selectBtn7.selected = YES;
        self.selectBtn8.selected = NO;
    }
    else {
        self.selectBtn6.selected = NO;
        self.selectBtn7.selected = NO;
        self.selectBtn8.selected = YES;
    }
    self.selectBtn1.selected = NO;
    self.selectBtn2.selected = NO;
}
@end
